package com.invest.controller;

import com.invest.common.annotation.Log;
import com.invest.common.core.controller.BaseController;
import com.invest.common.core.domain.AjaxResult;
import com.invest.common.core.page.TableDataInfo;
import com.invest.common.enums.BusinessType;
import com.invest.common.utils.poi.ExcelUtil;
import com.invest.domain.entity.CbData;
import com.invest.service.CbDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 可转债数据Controller
 *
 * @author yuch
 * @date 2025-01-05
 */
@Controller
@RequestMapping("/system/data")
public class CbDataController extends BaseController
{
    private String prefix = "system/data";

    @Autowired
    private CbDataService cbDataService;

    @RequiresPermissions("system:data:view")
    @GetMapping()
    public String data()
    {
        return prefix + "/data";
    }

    /**
     * 查询可转债数据列表
     */
    @RequiresPermissions("system:data:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list( CbData CbData)
    {
        startPage();
        List< CbData> list =  cbDataService.selectCbDataList( CbData);
        return getDataTable(list);
    }

    /**
     * 导出可转债数据列表
     */
    @RequiresPermissions("system:data:export")
    @Log(title = "可转债数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export( CbData  CbData)
    {
        List< CbData> list =  cbDataService.selectCbDataList( CbData);
        ExcelUtil< CbData> util = new ExcelUtil< CbData>( CbData.class);
        return util.exportExcel(list, "可转债数据数据");
    }




    /**
     * 修改可转债数据
     */
    @RequiresPermissions("system:data:edit")
    @GetMapping("/edit/{bondId}")
    public String edit(@PathVariable("bondId") String bondId, ModelMap mmap)
    {
         CbData  CbData =  cbDataService.selectCbDataByBondId(bondId);
        mmap.put("cbData",  CbData);
        return prefix + "/edit";
    }

    /**
     * 修改保存可转债数据
     */
    @RequiresPermissions("system:data:edit")
    @Log(title = "可转债数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave( CbData  CbData)
    {
        return toAjax( cbDataService.updateCbData( CbData));
    }

    /**
     * 删除可转债数据
     */
    @RequiresPermissions("system:data:remove")
    @Log(title = "可转债数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax( cbDataService.deleteCbDataByIds(ids));
    }
}
